package com.hl.sfzy.utils;

import com.hl.sfzy.exception.ProjectException;
import lombok.Data;

@Data
public class Result {
    private Integer code;
    private String message;
    private Object data;

    public Result(){}
    public Result(Integer code,String message, Object data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result success(){
        return  new Result(200, "操作成功", null);
    }

    public static Result success(Object data){
        return  new Result(200, "操作成功", data);
    }

    public static Result fail(int code){
        return  new Result(code, "操作失败！", null);
    }

    //自定义异常返回的结果
    public static Result defineError(ProjectException pe){
        Result result = new Result();
        result.setCode(pe.getCode());
        result.setMessage(pe.getMessage());
        result.setData(null);
        return result;
    }
}
